package com.app.designpattern.creation.factory.singlefactory

/**
 *
 * USER: zjw
 * DATA: 2019/4/8 0008
 * TIME: 上午 10:16
 */
class VideoFactory {
    /*fun getVideo(type: String): Video? {
        when (type) {
            "java" -> return JavaVideo()
            "python" -> return PythonVideo()
            else -> return null
        }
    }*/
    companion object {
        fun <T : Video> getVideo(c: Class<T>): T? {
            var video: Video? = null
            try {
                video = Class.forName(c.name).newInstance() as Video
            } catch (e: IllegalAccessException) {
                e.printStackTrace()
            } catch (e: InstantiationException) {
                e.printStackTrace()
            } catch (e: ClassNotFoundException) {
                e.printStackTrace()
            }

            return video as T?
        }
    }
}